package main.utils;

import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.layout.GridPane;

import java.util.List;

import static main.utils.RiverConstants.GRID_GAP;

public class GridDisplay {
    private GridPane pane = new GridPane();
    private Group display = new Group(pane);
    private int cols = 0;
    private int rows = 0;

    private double x;
    private double y;

    public GridDisplay() {
        pane.setHgap(GRID_GAP);
        pane.setVgap(GRID_GAP);
    }

    public void add(Node node, int col, int row) {
        if (col + 1 > cols) {
            cols = col + 1;
        }
        if (row + 1 > rows) {
            rows = row + 1;
        }
        pane.add(node, col, row);
    }

    public Group getDisplay() {
        return display;
    }

    public void clear() {
        pane.getChildren().clear();
    }

    public List<Node> getChildren() {
        return pane.getChildren();
    }

    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }

    public int getHeight() {
        return rows == 0 ? 0 : (rows * RiverConstants.CELL_SIZE + rows * RiverConstants.GRID_GAP - 1);
    }

    public int getWidth() {
        return cols == 0 ? 0 : (cols * RiverConstants.CELL_SIZE + cols * RiverConstants.GRID_GAP - 1);
    }
}
